<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="/kr/co/project1" prefix="util" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
function goSearch(){
	var frm = document.getElementById("frm");
	frm.action ='<c:url value="/board/list"/>';
	frm.submit();
}

function modifyForm(seq,boardCode){
	location.href='<c:url value="/board/getItem"/>?seq='+seq +"&boardCode="+boardCode ;
}

$(document).ready(function(){
	//전체 선택, 해제
	$("#checkAll").click(function(){
		if($("#checkAll").is(":checked")){
			$("input:checkbox[id=seqArr]:not(checked)").prop("checked", true); 
		}else{
			$("input:checkbox[id=seqArr]:checked").prop("checked", false); 
		}
	});
	
	// 아무거나 선택시 : 전체 해제 
    $(":checkbox").not("#checkAll").on({
        change : function (){
            if ( ! $(this).prop("checked") ) {
                $("#checkAll").prop("checked", false);
            }
        }
    });
	
    $("#deletes").click(function(){
    	var seqArr = new Array();
    	var seqs;
    	$("input[name=seqArr]:checked").each(function() {
    		seqs = $(this).val();
	    	for(var i=0;i<$(this).length;i++){
	    		seqArr[i] = seqs;
	    		console.log("seqArr"+[i]+"="+seqs);
	    	}
		});
    	
    	
    	var frm = document.getElementById("frm");
    	frm.action ='<c:url value = "/board/deletes"/>';
    	frm.submit();
    });
	
	
});
</script>

</head>
<body>

<form id="frm" method="post">
<input type="hidden" name="boardCode" value="${boardCode }"/>
	<div class="row">
	<table border="1">
		<thead>
			<tr>
				<td><input type="checkbox" id="checkAll" name="checkAll"></td>
				<td class="span2">순서</td>
				<td class="span2">제목</td>
				<td class="span2">작성자</td>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="item" items="${result.resultList}" varStatus="status">
				<tr>
					<td><input type="checkbox" id="seqArr" name="seqArr" value="${item.seq}"></td>
					<td>${status.count + ((result.curPage-1) * 10)} </td>
					<td><a href="javascript:modifyForm(${item.seq}, ${item.boardCode})">${item.bdTitle}</a></td>
					<td>${item.regId}</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	
	<select id="searchContent" name="searchContent">
		<option value="1">순번</option>
		<option value="2">제목</option>
	</select>
	<input type="text" id="searchText" name="searchText" >
	<input type="button" value="조회" class="btn btn-primary" onclick="javascript:goSearch();">
	<a class="btn btn-primary" type="button" href="getForm?boardCode=${boardCode}"> 새로등록</a>
	<a class="btn btn-primary" type="button" id="deletes"> 삭제</a>
	</div>
</form>
	<div style="text-align: center;">
		<c:url var="searchUri" value="/board/list?boardCode=${boardCode }"/>
		<util:paginator currPage="${result.curPage }" totalPages="${result.totalPage }" uri="${searchUri }"/>
	</div>


</body>
</html>